<?php
namespace notification\tools;

use EasyWeChat\Factory;
use EasyWeChat\Kernel\Messages\Text;

class WeWorkNotification implements NotificationInterface {

    protected $app;


    public function __construct($corp_id, $agent_id, $secret) {
        $config = [
            'corp_id' => $corp_id,
            'agent_id' => $agent_id, // 如果有 agend_id 则填写
            'secret'   => $secret,
        
            // 指定 API 调用返回结果的类型：array(default)/collection/object/raw/自定义类名
            'response_type' => 'array',
        
            'log' => [
                'level' => 'debug',
                'file' => __DIR__.'/wechat.log',
            ],
        ];
        
        $app = Factory::work($config);
        $this->app = $app;
                                  
    }

    public function sendText($message, $recipient) {
        $str = sprintf("%s\n\n%s", $message->title, $message->content);
        // 实现邮件发送逻辑
        return $this->app->messenger->message($str)->toUser($recipient)->send();
    }
}

